ARRAY INDEX TO QUEUE

This command will set the current array index to the first item in the array queue.

  Syntax
ARRAY INDEX TO QUEUE Array Name(0)
  Parameters
Array Name(0
Integer
The name of the array followed by a pair of brackets ( ). You can also insert a value of zero, i.e. arrayname(0)

  Returns

This command does not return a value.

  Description

Queues are a first in, first out data structure. You can imagine a queue as a line of people waiting for the bus. The last item of data added will be the last item of data to come off the queue.

  Example Code
EXAMPLE=dim a() as integer
empty array a()

print "Add 5 items to the queue"
for i=1 to 5
n = rnd(1000)
print " Adding "; n; " to the queue"
add to queue a()
a() = n
next i

print
PrintQueue()
print
print "Pop 2 items from the queue"

for i=1 to 2
print " Removing "; a(0); " from the queue"
remove from queue a()
next i

print
PrintQueue()
print

print "Add 5 more entries to the queue"
for i=0 to 4
n = rnd(1000)
print " Adding "; n; " to the queue"

add to queue a()
a() = n
next i

print
PrintQueue()
print

print "Now remove items until the queue is empty"
while array index valid( a() )
print " Removing "; a(0); " from the queue"
remove from queue a()
endwhile

print
PrintQueue()

wait key
end

function PrintQueue()
if array count( a() ) >= 0
print "The queue has "; array count( a() )+1; " items"
for i=0 to array count( a() )
print " Item "; i; " = "; a(i)
next i
else
print "The queue is empty"
endif
endfunction
  See also

CORE Commands Menu
Index